package com.tangjiali.listTopic3;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        list.add(new Student("张三", 21, "男"));
        list.add(new Student("李四", 22, "女"));
        list.add(new Student("王五", 19, "男"));
        int maxAge = list.get(0).getAge();      //最大年龄
        int maxAgeId = 0;   //最大年龄对应索引
        for (int i = 1; i < list.size(); i++) {
            if (list.get(i).getAge() > maxAge) {
                maxAge = list.get(i).getAge();
                maxAgeId = i;
            }
        }
        list.get(maxAgeId).setName("小猪佩奇"); //获取对象并且修改姓名

        list.forEach(student -> System.out.println(student));
    }
}
